<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{$title}-{$Think.lang.web_name}</title>
    {include file="comm/header"/}
</head>
<body>
{include file="comm/left_menu"/}
{include file="comm/top_menu"/}
<div class="container main">
    <div class="col-sm-12 border-bottom text-right"><a class="btn btn-primary mgr-10" href="/Models/model_edit/id/{$model._model_id}"><i class="fa fa-plus"></i>&nbsp;{$Think.lang.model_add}</a></div>
    <div class="col-sm-12">
        <div class="col-sm-12 margin-bottom-10"></div>
        <table class="table table-striped table-bordered table-hover" id="myTable">
            <thead>
            <tr>
                <th>{$Think.lang.model_id}</th>
                <th>{$Think.lang.model_name}</th>
                <th>{$Think.lang.model_field_id}</th>
                <th>{$Think.lang.manager}</th>
            </tr>
            </thead>

            <tbody>
            {foreach name="model_list" key="key" id="v" index="i"}
            <tr>
                <td style="width: 160px;">{$v.model_id}</td>
                <td>
                    <input type="text" class="input_init" data-field="model_name" data-id="{$v.model_id}" value="{$v.model_name}" data-former="{$v.model_name}">
                </td>
                <td>{$v.model_field_id}</td>
                <td style="width: 160px;">
                    <a href="/Models/model_edit/id/{$v.model_id}" class="btn btn-primary btn-xs mgr-10"><i class="fa fa-pencil"></i> {$Think.lang.edit}</a>
                    <a href="javascript:del('/Models/model_del/id/{$v.model_id}')" class="btn btn-danger btn-xs"><i class="fa fa-times"></i> {$Think.lang.del}</a>
                </td>
            </tr>
            {/foreach}
            </tbody>
        </table>
    </div>
</div>
{include file="comm/footer"/}
<script type="text/javascript">
    $(function () {
        var inputs = $(".input_init");
        inputs.on("blur",function (e) {
            if(this.getAttribute("data-type")==="number"){
                this.setAttribute("type","text");
            }
            /*异步修改部分 start*/
            var v = this.value;
            var f = this.getAttribute("data-field");
            var id = this.getAttribute("data-id");
            var former = this.getAttribute("data-former");
            var token = LO.get("token");
            if(v == former){ return false;}
            $.get("/Models/model_edit_ajax/",{
                id:id, f:f, v:v, token:token
            },function (data) {
                try {
                    data = $.parseJSON(data);
                    if (data.data == 1){
                        tips_success("修改成功",function () {
                            location.reload(true);
                        });
                    }else{
                        tips_success("权限不足");
                    }
                }catch (e) {
                    tips_fail("数据错误");
                }
            });
            /*异步修改部分 end */
        });
        inputs.on("focus",function (e) {
            if(this.getAttribute("data-type")==="number"){
                this.setAttribute("type","number");
            }
        });
    });

</script>
</body>
</html>